package com.ls.markt.service.admin.impl;

import com.ls.markt.dao.admin.CoachMapper;
import com.ls.markt.model.admin.Coach;
import com.ls.markt.repository.admin.CoachRepository;
import com.ls.markt.service.admin.CoachService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CoachServiceImpl implements CoachService {

    @Resource
    private CoachMapper mapper;

    @Resource
    private CoachRepository coachRepository;

    @Override
    public void saveCoach(Coach coach) {
        coachRepository.save(coach);
    }

    @Override
    public Page<Coach> listCoachs(PageRequest pageRequest) {
        return coachRepository.findAll(pageRequest);
    }

    @Override
    public List<Coach> listCoachs() {
        return coachRepository.findAll();
    }

    @Override
    public void removeCoach(Long[] ids) {
        for (Long id: ids) {
            coachRepository.deleteById(id);
        }
    }

    @Override
    public Coach getCoachById(Long id) {
        return coachRepository.getOne(id);
    }

    @Override
    public String getNameById(Long id) {
        return mapper.getNameById(id);
    }
}
